﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage.Table;

namespace Project.Library
{

    public interface IData
    {
        int Init(String ConnectionString); // Used To Initilize Cloud Storage 
        int Create<T>(String TableName, ref T oClass) where T : TableEntity, new();
        List<T> Read<T>(String TableName,String PartitionKey="", String RowKey="") where T : TableEntity, new ();
        int Update<T>(String TableName, ref T oClass) where T : TableEntity;
        int Delete(String TableName);
        int Delete<T>(String TableName, String PartitionKey, String RowKey) where T : TableEntity;
    }

    public class Data
    {
        private IData oData;
        public Data(IData oData)
        {
            this.oData= oData;
        }

        public int Init(String ConnectionString)
        {
            return oData.Init(ConnectionString);
        }


        public int Create<T>(String TableName, ref T oClass) where T : TableEntity, new()
        {
            return oData.Create(TableName, ref oClass);
        }

        public List<T> Read<T>(String TableName,String PartitionKey, String RowKey) where T : TableEntity, new()
        {
            return oData.Read<T>(TableName,PartitionKey,RowKey);
        }

        public int Update<T>(String TableName, ref T oClass) where T : TableEntity
        {
            return oData.Update(TableName, ref oClass);
        }

        public int Delete<T>(String TableName, String PartitionKey, String RowKey) where T : TableEntity
        {
            return oData.Delete<TableEntity>(TableName, PartitionKey, RowKey);
        }

        public int Delete(String TableName)
        {
            return oData.Delete(TableName);
        }

    }
}
